<?php

//防止恶意调用
if (!defined('IN_MOD'))
{
    die('Hacking attempt');
}

use think\Db;

// 获取购物车中的商品列表
function getcartdatalist($shopid=NULL)
{
	global $configmember;
	
	// 购物车列表
	$modulewhere=array();
	$modulewhere["tablename"]="modulepara_cart";
	$modulewhere["arrayclass"]=$configmember['id'];
	$modulewhere["bigclassname"]="userid";
	if(isset($shopid))$modulewhere["where"]="supplier_id='".$shopid."'";
	$modulewhere["order"]='id DESC';
	$cartlist=modulepara("configmodule",$modulewhere,1);
	
	// 遍历购物车数据
	foreach($cartlist as $key=>$val)
	{
		// 购物车商品属性
		$goods_attr = getstrtoarr(",",$val['goods_attr']);
		foreach($goods_attr as $k=>$v)
		{
			$pinfo = getstrtoarr("-",$v);
			$cartlist[$key]["goods_attr_arr"][$pinfo[0]] = $pinfo[1];
		}
	}
	
	// 将购物车中商品根据店铺ID进行分类
	$cartshoplistdata = getcartshoplist($cartlist);
	$cartshoplist = $cartshoplistdata['shopcartlist'];
	$shopids = $cartshoplistdata['shopids'];
	$shopcount = $cartshoplistdata['shopcount'];
	
	// 统计商品总金额
	$goodstotalprice = 0;
	foreach($cartlist as $key=>$val)
	{
		$goodstotalprice += $val['price'] * $val['number'];// 商品总金额
		$goodsoldtotalprice += $val['goodsprice'] * $val['number'];// 原价总金额	
		
		// 可参加订单活动商品总价格	
		if($val['hdstatus'] == 0)
		{
			$orderhdtotalprice += $val['price'] * $val['number'];
		}	
	}
	
	// 购物车商品列表
	$cartgoodslist = array();
	foreach($cartlist as $key=>$val)
	{
		$cartgoodslist[$val['listid']] = $val;
		
		// 商品组总价格
		if(empty($cartgoodslist[$val['listid']]['totalprice']))
		{
			$cartgoodslist[$val['listid']]['totalprice'] = 0;
		}
		$cartgoodslist[$val['listid']]['totalprice'] += $val['price'] * $val['number'];
	}
	
	// 购物车中的积分兑换商品
	$integralgoodsgroup = array();
	if($cartlist[0]['integralgoods'] == 1)
	{
		$integralgoodsgroup['integralgoods'] = 1;
		$integralgoodsgroup += $cartlist[0];
	}
	
	return array('cartlist' => $cartlist, 'cartshoplist' => $cartshoplist, 'shopids'=> $shopids, 'shopcount'=> $shopcount, 'cartgoodslist' => $cartgoodslist, 'goodstotalprice'=>$goodstotalprice, 'goodsoldtotalprice'=>$goodsoldtotalprice, 'integralgoodsgroup'=>$integralgoodsgroup);
}

// 获取订单活动列表
function getorderactivitylist($shopid=NULL,$outfee=array(),$otherfee=array())
{
	$activitylist = array();
	$hdtype_name = getdesignatedname("hdtype");
	$yhhdtype_name = getdesignatedname("yhhdtype");
	$tomoney_name = getdesignatedname("tomoney");
	$hdgoodsids_name = getdesignatedname("hdgoodsids");
	$endtime_name = getdesignatedname("datetype_endtime");
	
	// 购物车商品列表
	$cartdatalist=getcartdatalist($shopid);
	$cartlist = $cartdatalist['cartlist'];
	$goodstotalprice = $cartdatalist['goodstotalprice'];
	$goodsoldtotalprice = $cartdatalist['goodsoldtotalprice'];
	$cartgoodslist = $cartdatalist['cartgoodslist'];
	$cartshoplist = $cartdatalist['cartshoplist'];
	
	// 当购物车中的商品为积分兑换商品时禁止使用任何活动
	$integralgoodsgroup = $cartdatalist['integralgoodsgroup'];
	if(!empty($integralgoodsgroup) && $integralgoodsgroup['integralgoods'] == 1)
	{
		return array("list"=>'',"price"=>round($integralgoodsgroup['price'] + $otherfee['psfee'], 2),"orderprice"=>$integralgoodsgroup['price'],
		"goodsprice"=>$integralgoodsgroup['goodsprice'],"goodsoldprice"=>$integralgoodsgroup['goodsprice'],"discountprice"=>0,"dkprice"=>0);
	}
	
	// 初始化价格
	$yhprice = $goodstotalprice;// 折扣后的价格
	$discountprice = 0;// 折扣总金额
	
	// 商品组列表指定商品活动
	$goodsyhmoney = 0;
	$goodsexpression = 0;
	foreach($cartgoodslist as $goodsid=>$goodsinfo)
	{
		// 指定商品满减活动
		$goodsactivity_less = array();
		$modulewhere=array();
		$modulewhere["tablename"]="fastxcms_portal_post_promotion";
		$modulewhere["dataid"]=137;
		$modulewhere["dataidname"]="category_id";
		$modulewhere["where"]="$endtime_name >= ".time()." and $hdtype_name = '1' and $yhhdtype_name = '0' and concat(',',$hdgoodsids_name,',') like '%,".$goodsid.",%' and $tomoney_name <= ".$goodsinfo['totalprice']." order by `$tomoney_name`+0 desc";
		$goodsactivity_less=modulepara("datainfo",$modulewhere);
		$parameterinfo = getmoduleparameter($goodsactivity_less['id'], 137);
		if($parameterinfo)$goodsactivity_less += $parameterinfo;
		if(is_array($goodsactivity_less))
		{
			// 活动优惠总金额
			$goodsyhmoney += $goodsactivity_less['yhmoney'];
		}
	
		// 指定商品满额打折活动
		$goodsactivity_dis = array();
		$modulewhere=array();
		$modulewhere["tablename"]="fastxcms_portal_post_promotion";
		$modulewhere["dataid"]=137;
		$modulewhere["dataidname"]="category_id";
		$modulewhere["where"]="$endtime_name >= ".time()." and $hdtype_name = '1' and $yhhdtype_name = '1' and concat(',',$hdgoodsids_name,',') like '%,".$goodsid.",%' and $tomoney_name <= ".$goodsinfo['totalprice']." order by `$tomoney_name`+0 desc";
		$goodsactivity_dis=modulepara("datainfo",$modulewhere);
		$parameterinfo = getmoduleparameter($goodsactivity_dis['id'], 137);
		if($parameterinfo)$goodsactivity_dis += $parameterinfo;
		if(is_array($goodsactivity_dis))
		{
			// 活动优惠总金额
			$goodsexpression += $goodsinfo['totalprice'] - ($goodsinfo['totalprice'] * ($goodsactivity_dis['expression'] / 10));
		}
	}
	// 指定商品满减活动
	if($goodsyhmoney > 0)
	{
		$activitylist['goodsactivity_less']['name'] = "商品减价";
		$activitylist['goodsactivity_less']['money'] = $goodsyhmoney;
		$yhprice = $yhprice - $goodsyhmoney;// 计算优惠价格
		$discountprice = $discountprice + $goodsyhmoney;// 计算折扣总金额
	}
	
	// 指定商品满额打折活动
	if($goodsexpression > 0)
	{
		$activitylist['goodsactivity_dis']['name'] = "商品折扣";
		$activitylist['goodsactivity_dis']['money'] = $goodsexpression;
		$yhprice = $yhprice - $goodsexpression;// 计算优惠价格
		$discountprice = $discountprice + $goodsexpression;// 计算折扣总金额
	}
	
	// 店铺组列表订单活动
	$orderyhmoney = 0;
	$orderexpression = 0;
	foreach($cartshoplist as $shopid=>$shoplist)
	{
		// 可参加订单活动商品总价格存在时
		if($shoplist['orderhdtotalprice'] > 0)
		{
			// 订单满减活动
			$orderactivity_less = array();
			$modulewhere=array();
			$modulewhere["tablename"]="fastxcms_portal_post_promotion";
			$modulewhere["dataid"]=137;
			$modulewhere["dataidname"]="category_id";
			$modulewhere["where"]="$endtime_name >= ".time()." and $hdtype_name = '0' and $yhhdtype_name = '0' and $tomoney_name <= ".$shoplist['orderhdtotalprice']." and supplier_id = '".$shopid."' order by `$tomoney_name`+0 desc";// 当前店铺数据
			$orderactivity_less=modulepara("datainfo",$modulewhere);
			$parameterinfo = getmoduleparameter($orderactivity_less['id'], 137);
			if($parameterinfo)$orderactivity_less += $parameterinfo;
			if(is_array($orderactivity_less))
			{
				// 活动优惠总金额
				$orderyhmoney += $orderactivity_less['yhmoney'];
			}

			// 订单满额打折活动
			$orderactivity_dis = array();
			$modulewhere=array();
			$modulewhere["tablename"]="fastxcms_portal_post_promotion";
			$modulewhere["dataid"]=137;
			$modulewhere["dataidname"]="category_id";
			$modulewhere["where"]="$endtime_name >= ".time()." and $hdtype_name = '0' and $yhhdtype_name = '1' and $tomoney_name <= ".$shoplist['orderhdtotalprice']." and supplier_id = '".$shopid."' order by `$tomoney_name`+0 desc";// 当前店铺数据
			$orderactivity_dis=modulepara("datainfo",$modulewhere);
			$parameterinfo = getmoduleparameter($orderactivity_dis['id'], 137);
			if($parameterinfo)$orderactivity_dis += $parameterinfo;
			if(is_array($orderactivity_dis))
			{
				// 活动优惠总金额
				$orderexpression += $shoplist['orderhdtotalprice'] - ($shoplist['orderhdtotalprice'] * ($orderactivity_dis['expression'] / 10));
			}
		}
	}
	// 订单满减活动
	if($orderyhmoney > 0)
	{
		$activitylist['orderactivity_less']['name'] = "订单减价";
		$activitylist['orderactivity_less']['money'] = $orderyhmoney;
		$yhprice = $yhprice - $orderyhmoney;// 计算优惠价格
		$discountprice = $discountprice + $orderyhmoney;// 计算折扣总金额
	}

	// 订单满额打折活动
	if($orderexpression > 0)
	{
		$activitylist['orderactivity_dis']['name'] = "订单折扣";
		$activitylist['orderactivity_dis']['money'] = $orderexpression;
		$yhprice = $yhprice - $orderexpression;// 计算优惠价格
		$discountprice = $discountprice + $orderexpression;// 计算折扣总金额
	}
	
	// 优惠券活动
	if($outfee['yhjfee'])
	{
		$yhprice = $yhprice - $outfee['yhjfee'];
	}
	
	// 设置订单总金额
	$orderprice = $yhprice;
	
	// 其它费用 *************************************************************************
	
	// 使用积分抵扣
	$dkprice = 0;
	if($otherfee['useintegral'])
	{
		$dkprice = getintegraltomoney($otherfee['useintegral']);
		$yhprice = $yhprice - $dkprice;
	}
	
	// 配送费用
	if($otherfee['psfee'])
	{
		$yhprice = $yhprice + $otherfee['psfee'];
	}
	
	return array("list"=>$activitylist,"price"=>round($yhprice, 2),"orderprice"=>round($orderprice, 2),"goodsprice"=>round($goodstotalprice, 2),"goodsoldprice"=>round($goodsoldtotalprice, 2),"discountprice"=>round($discountprice, 2),"dkprice"=>round($dkprice, 2));	
}

// 商品活动列表
function getgoodsactivitylist($goodsid)
{
	global $configinfo;
	
	$activitylist = array();
	$hdtype_name = getdesignatedname("hdtype");
	$yhhdtype_name = getdesignatedname("yhhdtype");
	$tomoney_name = getdesignatedname("tomoney");
	$hdgoodsids_name = getdesignatedname("hdgoodsids");
	$endtime_name = getdesignatedname("datetype_endtime");
	
	// 当前商品
	$hdstatus_name = getdesignatedname("hdstatus");
	$integralstatus_name = getdesignatedname("integralstatus");
	$modulewhere=array();
	$modulewhere["tablename"]="fastxcms_portal_post_product";
	$modulewhere["dataid"]=$goodsid;
	$modulewhere["dataidname"]=$configinfo['article_id'];
	$goodsinfo=modulepara("datainfo",$modulewhere);
	$hdstatus = $goodsinfo[$hdstatus_name];// 活动状态 是否参与订单活动
	
	// 当商品为积分兑换商品时禁止使用任何活动
	if($goodsinfo[$integralstatus_name] == 1)
	{
		return NULL;
	}
	
	// 订单优惠券列表
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_coupon";
	$modulewhere['arrayclass'] = 136;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '0' and supplier_id = '".$goodsinfo['supplier_id']."'";// 当前店铺数据
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "default";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 136;
	$order_coupon_list = configmodule($modulewhere);
	
	// 商品优惠券列表
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_coupon";
	$modulewhere['arrayclass'] = 136;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '1' && concat(',',$hdgoodsids_name,',') like '%,".$goodsid.",%'";
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "default";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 136;
	$goods_coupon_list = configmodule($modulewhere);
	
	// 订单满减活动
	$orderactivity_less = array();
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_promotion";
	$modulewhere['arrayclass'] = 137;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '0' and $yhhdtype_name = '0' and supplier_id = '".$goodsinfo['supplier_id']."'";// 当前店铺数据
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "`$tomoney_name`+0 asc";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 137;
	$orderactivity_less = configmodule($modulewhere);
	
	// 订单满额打折活动
	$orderactivity_dis = array();
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_promotion";
	$modulewhere['arrayclass'] = 137;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '0' and $yhhdtype_name = '1' and supplier_id = '".$goodsinfo['supplier_id']."'";// 当前店铺数据
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "`$tomoney_name`+0 asc";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 137;
	$orderactivity_dis = configmodule($modulewhere);
	
	// 商品满减活动
	$goodsactivity_less = array();
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_promotion";
	$modulewhere['arrayclass'] = 137;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '1' and $yhhdtype_name = '0' and concat(',',$hdgoodsids_name,',') like '%,".$goodsid.",%'";
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "`$tomoney_name`+0 asc";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 137;
	$goodsactivity_less = configmodule($modulewhere);
	
	// 商品满额打折活动
	$goodsactivity_dis = array();
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_portal_post_promotion";
	$modulewhere['arrayclass'] = 137;
	$modulewhere['bigclassname'] = 'category_id';
	$modulewhere['dataidname'] = 'id';
	$modulewhere['timearr'] = array("endtimename"=>$endtime_name,"endtime"=>time());
	$modulewhere['where'] = "$hdtype_name = '1' and $yhhdtype_name = '1' and concat(',',$hdgoodsids_name,',') like '%,".$goodsid.",%'";
	$modulewhere['limit'] = "all";
	$modulewhere['order'] = "`$tomoney_name`+0 asc";
	$modulewhere['plistok'] = 1;
	$modulewhere['topid'] = 137;
	$goodsactivity_dis = configmodule($modulewhere);
	
	// 当商品活动存在时使用商品活动，否则使用订单活动
	$coupon_list = !empty($goods_coupon_list) ? $goods_coupon_list : $order_coupon_list;
	$activity_less = !empty($goodsactivity_less) || $hdstatus == 1 ? $goodsactivity_less : $orderactivity_less;
	$activity_dis = !empty($goodsactivity_dis) || $hdstatus == 1 ? $goodsactivity_dis : $orderactivity_dis;
	
	return array('couponlist' => $coupon_list, 'couponcount' => $coupon_list[0]['count'], 'activity_less_list'=>$activity_less, 'activity_dis_list'=>$activity_dis);
}

// 获取会员对应等级价格
function getmemberrankprice($goodsprice)
{
	global $configmember;
	
	$price = $goodsprice;
	
	$rankinfo = $configmember['rankinfo'];
	if($rankinfo && $rankinfo['discount'] > 0)
	{
		$price = $goodsprice * $rankinfo['discount'];
	}
	
	return round($price, 2);
}

// 计算商品本身优惠折扣后价格（会员等级或促销价格等）
function getgoodsdiscountprice($goodsprice,$goodsid)
{
	global $configinfo;
	
	$promotestatus_name = getdesignatedname("promotestatus");// 促销状态
	$promotetime_name = getdesignatedname("datetype_promotetime");// 促销时间
	$integralstatus_name = getdesignatedname("integralstatus");// 积分兑换
	
	// 当前商品
	$modulewhere=array();
	$modulewhere["tablename"]="fastxcms_portal_post_product";
	$modulewhere["dataid"]=$goodsid;
	$modulewhere["dataidname"]=$configinfo['article_id'];
	$goodsinfo=modulepara("datainfo",$modulewhere);
	$parameterinfo = getmoduleparameter($goodsinfo['id'], 3);
	$goodsinfo = hbarray($goodsinfo,$parameterinfo);
	
	// 当商品为积分兑换商品时禁止使用任何活动
	if($goodsinfo[$integralstatus_name] == 1)
	{
		return $goodsprice;
	}

	// 促销价格
	if($goodsinfo[$promotestatus_name] == 1 && $goodsinfo["original_".$promotetime_name] >= time())
	{
		if($goodsinfo['promotetype'] == 1)
		{
			$price = $goodsprice - ($goodsprice * ($goodsinfo['promoteprice'] / 10));
		}else{
			$price = $goodsprice - $goodsinfo['promoteprice'];	
		}
		
	// 会员等级价格
	}else{
		$price = getmemberrankprice($goodsprice);
	}
	
	return round($price, 2);
}

// 获取当前会员订单商品可使用优惠券列表
function getmemberusecouponlist($shopid=0)
{
	// 购物车商品列表
	$cartdatalist = getcartdatalist($shopid);
	$cartgoodslist = $cartdatalist['cartgoodslist'];
	$cartlist = $cartdatalist['cartlist'];
	$cartshoplist = $cartdatalist['cartshoplist'];
	
	// 当购物车中的商品为积分兑换商品时禁止使用任何活动
	$integralgoodsgroup = $cartdatalist['integralgoodsgroup'];
	if(!empty($integralgoodsgroup) && $integralgoodsgroup['integralgoods'] == 1)
	{
		return NULL;	
	}
	
	$coupon_list = array();
	
	// 订单优惠券列表
	$modulewhere=array();
	$modulewhere['tablename'] = "fastxcms_user_coupon";
	$modulewhere['arrayclass'] = $configmember['id'];
	$modulewhere['bigclassname'] = "userid";
	$modulewhere['timearr'] = array("endtimename"=>"endtime","endtime"=>time());
	$modulewhere['where'] = "hdtype = '0' and status = 0 and tomoney <= ".$cartshoplist[$shopid]['totalprice']." and supplier_id = '".$shopid."'";// 当前店铺数据
	$modulewhere['limit'] = "all";
	$modulewhere['langallok'] = 1;
	$modulewhere['order'] = "default";
	$order_coupon = configmodule($modulewhere);
	if(!empty($order_coupon))$coupon_list = hbarray($coupon_list,$order_coupon);
	
	// 商品优惠券列表
	foreach($cartgoodslist as $goodsid=>$goodsinfo)
	{
		$modulewhere=array();
		$modulewhere['tablename'] = "fastxcms_user_coupon";
		$modulewhere['arrayclass'] = $configmember['id'];
		$modulewhere['bigclassname'] = "userid";
		$modulewhere['timearr'] = array("endtimename"=>"endtime","endtime"=>time());
		$modulewhere['where'] = "hdtype = '1' && concat(',',goodsids,',') like '%,".$goodsid.",%' and status = 0 and tomoney <= ".$goodsinfo['totalprice'];
		$modulewhere['limit'] = "all";
		$modulewhere['langallok'] = 1;
		$modulewhere['order'] = "default";
		$goods_coupon = configmodule($modulewhere);
		if(!empty($goods_coupon))$coupon_list = hbarray($coupon_list,$goods_coupon);
	}

	$couponlistgroup = array();
	foreach($coupon_list as $key=>$val)
	{
		$couponlistgroup[$val['id']] = $val;
	}
	
	return $couponlistgroup;
}

// 修改会员金额
function updatemembermoney($userid,$money,$type=1,$action="+")
{	
	$modulewhere=array();
	$modulewhere["tablename"]='fastxcms_user';
	$modulewhere["dataid"]=$userid;
	$modulewhere["dataidname"]='id';
	$memberinfo=modulepara("datainfo",$modulewhere);
	
	$data = array();
	if($type == 1)$data['balance'] = $action == "+" ? $memberinfo['balance'] + $money : $memberinfo['balance'] - $money;// 余额
	if($type == 2)$data['score'] = $action == "+" ? $memberinfo['score'] + $money : $memberinfo['score'] - $money;// 积分
	$res = updatedata("fastxcms_user", $data, 'id', $userid);
	
	return $res;
}

// 改变订单状态
function order_paid($order_sn, $status)
{
	global $configinfo;
	
	$orderstatus = "orderstatus";
	
	// 获取当前订单信息
	$modulewhere=array();
	$modulewhere["tablename"]='fastxcms_portal_post_order';
	$modulewhere["dataid"]=109;
	$modulewhere["dataidname"]='category_id';
	$modulewhere["where"]='id = "'.$order_sn.'" or post_title = "'.$order_sn.'"';
	$orderinfo=modulepara("datainfo",$modulewhere);
	
	// 修改订单状态
	if(!empty($orderinfo))
	{
		updatedata('fastxcms_portal_post_order',"`".$orderstatus."` = '".$status."'",'id',$orderinfo['id']);
	}
}

// 获取购物车中的赠送积分总数
function getgiveintegralnumber($shopid=NULL)
{
	// 购物车商品列表
	$cartdatalist=getcartdatalist($shopid);
	$cartlist = $cartdatalist['cartlist'];
	
	// 统计商品赠送积分总数
	$goodstotalintegral = 0;
	foreach($cartlist as $key=>$val)
	{
		$giveintegral = $val['giveintegral'] == -1 ? $val['goodsprice'] : $val['giveintegral'];// 赠送积分为-1时按商品价格赠送
		$goodstotalintegral += $giveintegral * $val['number'];// 赠送积分总数
	}	
	
	return $goodstotalintegral;
}

// 获取购物车中的可使用积分抵扣总数
function getintegraldknumber($shopid=NULL)
{
	global $configbase;
	
	// 购物车商品列表
	$cartdatalist=getcartdatalist($shopid);
	$cartlist = $cartdatalist['cartlist'];
	
	// 统计商品可使用积分抵扣总数
	$totalintegralmoney = 0;
	foreach($cartlist as $key=>$val)
	{
		$totalintegralmoney += $val['integraldkmoney'] * $val['number'];// 可使用抵扣积分总价格
	}
	
	$totalintegralnumber = $totalintegralmoney * $configbase['shopconfig']['integralratio'];// 可使用抵扣积分总数量
	
	return array('integralmoney' => $totalintegralmoney, 'integralnumber' =>$totalintegralnumber);
}

// 积分抵扣换算比例
function getintegraltomoney($integralnumber)
{
	global $configbase;
	
	$dkmoney = $integralnumber / $configbase['shopconfig']['integralratio'];
	
	return $dkmoney;
}

// 积分记录
function insertintegrallog($integral)
{
	global $configmember;
	
	Db::name('user_score_log')->insert([
		'user_id'     => $configmember['id'],
		'create_time' => time(),
		'action'      => 'goods',
		'score'       => $integral,
		'coin'        => 0,
	]);	
}

// 钱包操作记录
function moneyoperloglist($userid, $type, $content, $money)
{
	$moduledata = array();
	$moduledata['userid'] = $userid;
	$moduledata['type'] = $type;
	$moduledata['content'] = $content;
	$moduledata['time'] = time();
	$moduledata['money'] = $money;
	
	$insert_id = insertdata('modulepara_user_money_log',$moduledata);
	
	return $insert_id;
}

// 当前店铺信息
function getsupplierinfo($shopid)
{
	if($shopid > 0)
	{
		$modulewhere=array();
		$modulewhere["tablename"]='fastxcms_user';
		$modulewhere["dataid"]=$shopid;
		$modulewhere["dataidname"]='id';
		$supplierinfo=modulepara("datainfo",$modulewhere);
		$supplierinfo['shop_name'] = $supplierinfo['user_login'];
	}else{
		$supplierinfo['id'] = 0;
		$supplierinfo['shop_name'] = '平台自营';
	}
	
	return $supplierinfo;
}

// 将购物车中商品根据店铺ID进行分类
function getcartshoplist($cartlist)
{
	$shopcartlist = array();
	foreach($cartlist as $key=>$val)
	{
		$shopcartlist[$val['supplier_id']]['id'] = $val['supplier_id'];
		$shopcartlist[$val['supplier_id']]['shop_name'] = $val['shop_name'];
		
		// 店铺总价格
		if(empty($shopcartlist[$val['supplier_id']]['totalprice']))
		{
			$shopcartlist[$val['supplier_id']]['totalprice'] = 0;
		}
		$shopcartlist[$val['supplier_id']]['totalprice'] += $val['price'] * $val['number'];
		
		// 店铺可参加订单活动商品总价格	
		if(empty($shopcartlist[$val['supplier_id']]['orderhdtotalprice']))
		{
			$shopcartlist[$val['supplier_id']]['orderhdtotalprice'] = 0;
		}
		if($val['hdstatus'] == 0)
		{
			$shopcartlist[$val['supplier_id']]['orderhdtotalprice'] += $val['price'] * $val['number'];
		}
		
		$shopcartlist[$val['supplier_id']]['list'][] = $val;
	}
	
	// 遍历店铺购物车数据
	$shopidgroup = array();
	foreach($shopcartlist as $shopid=>$val)
	{
		// 获取购物车中所有店铺ID
		$shopidgroup[] = $shopid;
	}
	$shopids = getarrtostr(",",$shopidgroup);
	$shopcount = count($shopidgroup);
	
	return array("shopcartlist"=>$shopcartlist,"shopids"=>$shopids,"shopcount"=>$shopcount);
}
?>